<?php #20080105 http://www.framework.altervista.org/FrameWork/applications/_admin/02_regedit.inc
define('APPPREFERENCE','1.00');
/************************************************************************/
/* FrameWork  test preview                                              */
/* ==================================================================== */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

//carica la lingua se esiste
$lang=lang();
switch($lang){
    case "en":
	define("_ADMIN_PREFERENCE","ADMIN PREFERENCE");
	define("_CHANGE_PREFERENCES","change preferences");
	define("_SAVE_PREFERENCES","save preferences");
	define("_GEST_SAVE_PREFERENCES","GESTION RETURN POINT PREFERENCES");
	define("_CHANGE_PASSWORD","Change Password");
	define("_RETYPE_PASSWORD","Retype Password");
	define("_SET_PASSWORD","change password");
	define("_ADMINISTRATION_PRIVILEGE_REQUESTED", "administration privilege requested");
	define("_CHANGE","Change");
	define("_CONTINUA","Continue");
	break;
    default;
	define("_ADMIN_PREFERENCE","ADMIN PREFERENCE");
	define("_CHANGE_PREFERENCES","change preferences");
	define("_SAVE_PREFERENCES","save preferences");
	define("_GEST_SAVE_PREFERENCES","GESTIONE PUNTI DI RIPRISTINO CONFIGURAZIONE");
	define("_CHANGE_PASSWORD","Change Password");
	define("_SET_PASSWORD","change password");
	define("_RETYPE_PASSWORD","Retype Password");
	define("_ADMINISTRATION_PRIVILEGE_REQUESTED", "administration privilege requested");
	define("_CHANGE","Change");
	define("_CONTINUA","Continua");
	break;
}

loadlib("libArchivedir");
loadlib("libArchiveunzip");

?>

<?php if (admin_isadmin()) {
        admin_writelog(_ADMIN_PREFERENCE);
    ?>
    <p>


<style>
.fold
{
	border: 1px solid #808080;

}

</style>

<style>
	body {font-size:12px}
	.{font-family:arial;font-size:12px}
	h1 {cursor:hand;font-size:16px;margin-left:10px;line-height:10px}
	xmp {color:green;font-size:12px;margin:0px;font-family:courier;background-color:#e6e6fa;padding:2px}
</style>


<h3>regedit</h3>

<?php

    if (!file_exists("datas/saveconfig")) {mkdir("datas/saveconfig",0755);}


	$op=$_GET['op'];

	    // zip mensile-------------------------
	    if ($op=='config-unzip'){
        $nome_file=$_POST['elenco'];
        unzipdir("datas/saveconfig/".$nome_file);
        echo "il nome del file: ".$nome_file."<br>";

     }


	    if ($op=='log-mzip'){

	    $year=$_POST['year'];
	    $month=$_POST['month'];
	    $day=$_POST['day'];

	    echo "<b>zip di configurazione: $day - $month - $year </b><br />";
	    $nome_zip="datas/saveconfig/$year-$month-$day.zip";
	    $zip = new zip_file($nome_zip);
	    $zip->set_options(array('inmemory'=>"0",'overwrite'=>1,'storepaths','prepend','level','type'=>"zip"));

	    $dir = new DeepDir();
	    $dir->setDir("datas/config");
	    $dir->load();
	    foreach($dir->files as $nf){
		$zip->add_files($nf);
	    }
	    echo "<br><b>add files config to zip ...done </b><br />";

	    $zip->create_archive();

	//    $dir = new DeepDir();
	//    $dir->setDir("datas/sb/".sb_get()."/logs/global/$year/$month");
	//    $dir->load();
	//    foreach($dir->files as $nf){
	//	unlink($nf);
	//    }
	//    echo "logs global...deleted <br />";

        admin_writelog(_SAVE_PREFERENCES);

	    echo "<br><br><b>scarica </b><a href='$nome_zip'>punto_di_ripristino.zip</a>\n";
	    echo "<br><br><b>torna a regedit</b> <a href='index.php?appname=$appname'>torna</a>\n";


	}
	else{

   	    if ($year=="")$year=date("Y");
	    if ($month=="")$month=date("m");
	    if ($day=="")$day=date("d");

       ?>


	    <table style="font-size:9;" border='0'>
	    <tr>
	    <td>
	    <fieldset >
        <b><legend> <?=_GEST_SAVE_PREFERENCES;?> </legend></b>

	    <form name='ziplog' action='index.php?appname=<?=$appname;?>&op=log-mzip'  method='POST'>
		    <b>Creazione punto di Ripristino Files di configurazione </b><br><br> year <select name='year' >
		    <option><?=$year?></option>
		    <?php
			for($i=2008;$i<=2030 ;$i++)
			    echo"<option>".substr("0".$i,-4)."</option>";
		    ?>
		 </select>

		month<select name='month'>
		    <option><?=$month?></option>
		    <?php
			for($i=1;$i<=12 ;$i++)
			    echo"<option>".substr("0".$i,-2)."</option>";
		    ?>
		 </select>

		day<select name='day'>
		    <option><?=$day?></option>
		    <?php
			for($i=1;$i<=31 ;$i++)
			    echo"<option>".substr("0".$i,-2)."</option>";
		    ?>
		 </select>
		<input type='submit' value='Crea Punto di Ripristino' />


	    </form>

        <hr>

        <?php
        echo "<form action='index.php?appname=$appname&op=config-unzip' method='post'>";
        // leggo elenco file dei sistemi inseriti
        echo "<b>Elenco Punti di Ripristino</b> <br /><br /><select name='elenco' >";
          $fd=opendir("datas/saveconfig");
        		    while (false !== ($nf= readdir($fd))){
        			if( is_file("datas/saveconfig/$nf") && $nf[0]!='.')
        			    echo "<option>$nf</option>\n";
        		    }
        		    closedir($fd);
        echo "		</select>";

        echo "        <input type='submit' value='Ripristina Configurazione' />";
        echo "    </form>";
        ?>
        
	    </fieldset>

	<?php } ?>
	    </td>
	    </tr>
	    </table>



	<link rel="STYLESHEET" type="text/css" href="../css/dhtmlXTree.css">
	<script  src="js/dhtmlxTree/js/dhtmlXCommon.js"></script>
	<script  src="js/dhtmlxTree/js/dhtmlXTree.js"></script>

	<table border='1'>
		<tr>
			<td valign="top" width="250">
                <div id="treeboxbox_tree" style="width:250; height:420;background-color:#f5f5f5;border :1px solid Silver;; overflow:auto;"></div>
			</td>
			<td valign="top" width="100%">
<?php

global $tree,$tree_i;
$tree_i=0;

function dirconfig($randpath,$myparent){
    global $tree,$tree_i;
    $fd=opendir("datas/config".$randpath);
    while (false !== ($nf= readdir($fd))){
        if ($nf[0]!='.' ){
            if (is_dir("datas/config".$randpath.$nf)){
           	    $tree[$tree_i++]=$nf;
           	    echo "tree.insertNewItem($myparent,$tree_i,\"$nf\",0,0,0,0,\"SELECT\");\n ";
                dirconfig($randpath.$nf."/",$tree_i);
            }
        }
    }
    closedir($fd);
}

?>

	<script>
			tree=new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
			tree.setImagePath("js/dhtmlxTree/imgs/");

            function tonclick(id){
                var ob;
                for (i=0;i<99;i++){
                    ob=document.getElementById(i);
                    if (ob)ob.style.display="none";
                }

                ob=document.getElementById(id);
                if (ob)ob.style.display="inline";
                //alert (id);
            }
	       tree.setOnClickHandler(tonclick);

	</script>

<?php

//_admin preference
global $tree_i;

$myparent=1;
$tree_i=1;

function read_reg($path,$subapp,$myparent){
    global $tree_i;
    $fd=opendir("$path");
    $i=0;
    while (false !== ($nf= readdir($fd))){
	   if ($nf[0]!='.' ){
	       $reg[$i++]=$nf;
	   }
    }
    fclose($fd);
    if (count($reg))sort($reg);

    echo"<div id='$tree_i' style=\"display:none;border:2;\" >\n";
    echo "<h3>".basename($path)."</h3>\n";
    if (count($reg)){
    foreach($reg as $nf){
	   if ($nf[0]!='.' ){
	       if (!is_dir("$path/$nf")){
                switch(substr($nf,0,2)){

        		    case "b-":
        			echo "<form action='index.php?appname=".appname()."&subapp=$subapp&op=change&nf=$path/$nf' method='post' class='table appl'>\n";
        			echo"<span id='option-$nf' title='option-$nf' >\n";
        			echo "<b>$nf</b>";
        			echo"<input type='checkbox' name='$nf'";
        			if(@join(@file("$path/$nf"))!="")echo "checked='on'";
        			echo "')>\n";
        			echo "<input type='submit' value='"._CHANGE."'>\n";
        			echo"<br/>\n";
        			echo"</span></form>\n";
        			break;

        		    case "e-":
        			echo "<b>$nf</b>";
        			echo "<form action='index.php?appname=".appname()."&subapp=$subapp&op=change&nf=$path/$nf' method='post' class='table appl'>\n";
        			echo"<span id='option-$nf' title='option-$nf' ><br/>\n";
        			echo " ERROR <input type='checkbox' name='$nf-E_ERROR'";
        			if(@join(@file("$path/$nf"))& E_ERROR)echo "checked='on'";
        			echo "')>\n";

        			echo " WARNING<input type='checkbox' name='$nf-E_WARNING'";
        			if(@join(@file("$path/$nf"))& E_WARNING)echo "checked='on'";
        			echo "')> \n";

        			echo " PARSE<input type='checkbox' name='$nf-E_PARSE'";
        			if(@join(@file("$path/$nf"))& E_PARSE)echo "checked='on'";
        			echo "')> \n";

        			echo " NOTICE<input type='checkbox' name='$nf-E_NOTICE'";
        			if(@join(@file("$path/$nf"))& E_NOTICE)echo "checked='on'";
        			echo "')> \n";

        			echo "<br/>\n";
        			echo " CORE_ERROR<input type='checkbox' name='$nf-E_CORE_ERROR'";
        			if(@join(@file("$path/$nf"))& E_CORE_ERROR)echo "checked='on'";
        			echo "')> \n";

        			echo " CORE_WARNING<input type='checkbox' name='$nf-E_CORE_WARNING'";
        			if(@join(@file("$path/$nf"))& E_CORE_WARNING)echo "checked='on'";
        			echo "')> \n";

        			echo " COMPILE_ERROR<input type='checkbox' name='$nf-E_COMPILE_ERROR'";
        			if(@join(@file("$path/$nf"))& E_COMPILE_ERROR)echo "checked='on'";
        			echo "')> \n";

        			echo " COMPILE_WARNING<input type='checkbox' name='$nf-E_COMPILE_WARNING'";
        			if(@join(@file("$path/$nf"))& E_COMPILE_WARNING)echo "checked='on'";
        			echo "')> \n";

        			echo "<br/>\n";
        			echo " USER_ERROR<input type='checkbox' name='$nf-E_USER_ERROR'";
        			if(@join(@file("$path/$nf"))& E_USER_ERROR)echo "checked='on'";
        			echo "')> \n";

        			echo " USER_WARNING<input type='checkbox' name='$nf-E_USER_WARNING'";
        			if(@join(@file("$path/$nf"))& E_USER_WARNING)echo "checked='on'";
        			echo "')> \n";

        			echo " USER_NOTICE<input type='checkbox' name='$nf-E_USER_NOTICE'";
        			if(@join(@file("$path/$nf"))& E_USER_NOTICE)echo "checked='on'";
        			echo "')> \n";

        			echo "<input type='submit' value='"._CHANGE."'>\n";
        			echo "<br/>\n";
        			echo" </span>\n";
        			echo"</form>\n";
        			break;

        		    default:
        			echo "<form action='index.php?appname=".appname()."&subapp=$subapp&op=change&nf=$path/$nf' method='post' class='table appl'>\n";
        			echo"<span id='option-$nf' title='option-$nf' >\n";
        			echo "<b>$nf</b> ";
        			echo"<input type='text' size='50%' name='$nf' value='".@join(@file("$path/$nf"))."'>\n";
        			echo "<input type='submit' value='"._CHANGE."'>\n";
        			echo"<br/>\n";
        			echo"</span>\n";
        			echo"</form>\n";
        			break;
                }
            }
        }
    }
    }
    echo "</div>\n";
    if (count($reg)){
    foreach($reg as $nf){
	   if ($nf[0]!='.' ){
	       if (is_dir("$path/$nf")){
                $tree_i++;
                echo "<script> tree.insertNewItem($myparent,$tree_i,\"$nf\",0,0,0,0,\"SELECT\"); </script>\n ";
                read_reg("$path/$nf",$subapp,$tree_i);
            }
        }
    }
}
}




?>

<?php
$op=$_GET['op'];
$nf=$_GET['nf'];
$b_nf=basename($nf);
if (substr($b_nf,0,2)=="e-"){
    $vnf=0;
    if ($_POST["$b_nf-E_ERROR"])$vnf=$vnf | E_ERROR;
    if ($_POST["$b_nf-E_WARNING"])$vnf=$vnf | E_WARNING;
    if ($_POST["$b_nf-E_PARSE"])$vnf=$vnf | E_PARSE;
    if ($_POST["$b_nf-E_NOTICE"])$vnf=$vnf | E_NOTICE;
    if ($_POST["$b_nf-E_CORE_ERROR"])$vnf=$vnf | E_CORE_ERROR;
    if ($_POST["$b_nf-E_CORE_WARNING"])$vnf=$vnf | E_CORE_WARNING;
    if ($_POST["$b_nf-E_COMPILE_ERROR"])$vnf=$vnf | E_COMPILE_ERROR;
    if ($_POST["$b_nf-E_COMPILE_WARNING"])$vnf=$vnf | E_COMPILE_WARNING;
    if ($_POST["$b_nf-E_USER_ERROR"])$vnf=$vnf | E_USER_ERROR;
    if ($_POST["$b_nf-E_USER_WARNING"])$vnf=$vnf | E_USER_WARNING;
    if ($_POST["$b_nf-E_USER_NOTICE"])$vnf=$vnf | E_USER_NOTICE;
}
else{
    $vnf=$_POST[$b_nf];
}

if ($op=='change'){
    $f=fopen("$nf","w");
    fwrite($f,$vnf);
    fclose($f);
    echo" dato <b>$vnf</b> inserito in <B>$nf</b> <br/>";
    echo "<h3 class='edit'><a href='index.php?appname=$container&subapp=$subapp'>"._CONTINUA."</a></h3>";
}
else{
    echo "<script> tree.insertNewItem(0,1,\"config\",0,0,0,0,\"SELECT\"); </script>\n ";
    read_reg("datas/config",$subapp,1);
    echo "<script>tonclick(1);</script>";
}
?>
			</td>
		</tr>
	</table>

</p>
    <?php }else{ ?>
	<p><?=_ADMINISTRATION_PRIVILEGE_REQUESTED?> </p>
    <?php } ?>
<hr/>

